<html>
<head><meta charset="utf-8"><title>counters for uncalled functions · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html">counters for uncalled functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217216520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216520">(Nov 19 2020 at 00:41)</a>:</h4>
<p>So <span class="user-mention" data-user-id="296355">@Rich Kadel</span> and I were talking about how to emit coverage counters set to 0 for functions which aren't called</p>



<a name="217216593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216593">(Nov 19 2020 at 00:42)</a>:</h4>
<p>the problem, as I understand it, is that a <code>MonoItem</code> never gets generated for these functions, so codegen never happens for them</p>



<a name="217216623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216623">(Nov 19 2020 at 00:43)</a>:</h4>
<p>Rich– it sounds like you were planning to put code in the partitioner that picks a codegen unit to emit these</p>



<a name="217216713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216713">(Nov 19 2020 at 00:44)</a>:</h4>
<p>as in this module? <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/monomorphize/partitioning/index.html"><code>rustc_mir::monomorphize::partitioning</code></a></p>



<a name="217216734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216734">(Nov 19 2020 at 00:45)</a>:</h4>
<p>I'm thinking that I could iterate over the CGUs here: <a href="https://github.com/rust-lang/rust/blob/bf66988aa1677d018928c271fed563792f921d28/compiler%2Frustc_codegen_ssa%2Fsrc%2Fbase.rs#L618">https://github.com/rust-lang/rust/blob/bf66988aa1677d018928c271fed563792f921d28/compiler%2Frustc_codegen_ssa%2Fsrc%2Fbase.rs#L618</a></p>



<a name="217216756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216756">(Nov 19 2020 at 00:45)</a>:</h4>
<p>Would -Z link-dead-code help with that? That's what tarpaulin does.</p>



<a name="217216818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216818">(Nov 19 2020 at 00:46)</a>:</h4>
<p>Or whatever link-dead-code does internally</p>



<a name="217216831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216831">(Nov 19 2020 at 00:46)</a>:</h4>
<p>collect a list of all <code>MonoItem</code>s in all CGUs, and  use an <code>ItemLikeVisitor</code> to find all <code>Fn</code> items, compare them, and any <code>Fn</code> without a <code>MonoItem</code> should be added to the coverage map in the first (just to pick one) CGU.</p>



<a name="217216843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216843">(Nov 19 2020 at 00:46)</a>:</h4>
<p>It doesn't appear to help</p>



<a name="217216850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216850">(Nov 19 2020 at 00:47)</a>:</h4>
<p>(-Z link-dead-code)</p>



<a name="217216975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217216975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217216975">(Nov 19 2020 at 00:48)</a>:</h4>
<p>(-C link-dead-code actually)</p>



<a name="217217109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217109">(Nov 19 2020 at 00:50)</a>:</h4>
<p>One example of the issue is <a href="https://github.com/richkadel/rust/blob/48ab271775c7f2abbd124d4775a8d29408c36700/src%2Ftest%2Frun-make-fulldeps%2Fcoverage%2Fasync.rs#L9-L14">https://github.com/richkadel/rust/blob/48ab271775c7f2abbd124d4775a8d29408c36700/src%2Ftest%2Frun-make-fulldeps%2Fcoverage%2Fasync.rs#L9-L14</a></p>



<a name="217217138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217138">(Nov 19 2020 at 00:51)</a>:</h4>
<blockquote>
<p>collect a list of all <code>MonoItem</code>s in all CGUs, and  use an <code>ItemLikeVisitor</code> to find all <code>Fn</code> items, compare them, and any <code>Fn</code> without a <code>MonoItem</code> should be added to the coverage map in the first (just to pick one) CGU.</p>
</blockquote>
<p>ok and I guess that would mean calling a coverageinfo method directly from rustc_codegen_ssa?</p>



<a name="217217158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217158">(Nov 19 2020 at 00:51)</a>:</h4>
<p>The async function body for <code>g()</code> is never invoked, so it's closure is never included as a <code>MonoItem</code></p>



<a name="217217300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217300">(Nov 19 2020 at 00:53)</a>:</h4>
<p><code>FunctionCoverage</code> is implemented in <code>rustc_codegen_ssa</code> actually. It should be fine.</p>



<a name="217217474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217474">(Nov 19 2020 at 00:56)</a>:</h4>
<p>yeah that's fine, just trying to get an idea</p>



<a name="217217650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217650">(Nov 19 2020 at 00:58)</a>:</h4>
<p>I was thinking that we might already do such a walk over HIR items in the mono item collector, but that's probably not right</p>



<a name="217217681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217681">(Nov 19 2020 at 00:59)</a>:</h4>
<p>we probably only "seed" it with public functions (or <code>main</code>) and collect the transitive closure of what they call</p>



<a name="217217822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217822">(Nov 19 2020 at 01:01)</a>:</h4>
<p>so while I think walking HIR in the codegen stage <em>feels</em> wrong to me, since I'm not aware of anything like that we do today</p>



<a name="217217890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217217890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217217890">(Nov 19 2020 at 01:02)</a>:</h4>
<p>it definitely seems like the simplest way of implementing this</p>



<a name="217218057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218057">(Nov 19 2020 at 01:04)</a>:</h4>
<p>..so, any objections? <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="217218062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218062">(Nov 19 2020 at 01:04)</a>:</h4>
<p>I might be able to implement it as a new query provider</p>



<a name="217218239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218239">(Nov 19 2020 at 01:06)</a>:</h4>
<p>That's how the original mono_items are created:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="n">query</span><span class="w"> </span><span class="n">collect_and_partition_mono_items</span><span class="p">(</span><span class="n">_</span>: <span class="nc">CrateNum</span><span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="217218254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218254">(Nov 19 2020 at 01:06)</a>:</h4>
<p>using the query system for caching might be helpful here</p>



<a name="217218267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218267">(Nov 19 2020 at 01:07)</a>:</h4>
<p>This seems appropriate</p>



<a name="217218277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218277">(Nov 19 2020 at 01:07)</a>:</h4>
<p>do we have a query for all of the function items in HIR?</p>



<a name="217218305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218305">(Nov 19 2020 at 01:07)</a>:</h4>
<p>I wouldn't be surprised if other code needs that</p>



<a name="217218383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218383">(Nov 19 2020 at 01:08)</a>:</h4>
<p>Maybe... I haven't seen that. Most code just writes an ItemLikeVisitor, from what I've seen (not that there are many examples of this)</p>



<a name="217218424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218424">(Nov 19 2020 at 01:09)</a>:</h4>
<p>A similar query may be:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="n">query</span><span class="w"> </span><span class="n">all_traits</span><span class="p">(</span><span class="n">_</span>: <span class="nc">CrateNum</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="na">tcx</span> <span class="p">[</span><span class="n">DefId</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>



<a name="217218430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218430">(Nov 19 2020 at 01:09)</a>:</h4>
<p>could be that it's cheap enough to do the crawl every time, or maybe every use is a bit different</p>



<a name="217218533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218533">(Nov 19 2020 at 01:10)</a>:</h4>
<p>Maybe this one would be good:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="n">query</span><span class="w"> </span><span class="n">mir_keys</span><span class="p">(</span><span class="n">_</span>: <span class="nc">CrateNum</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">FxHashSet</span><span class="o">&lt;</span><span class="n">LocalDefId</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
</code></pre></div>



<a name="217218587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218587">(Nov 19 2020 at 01:11)</a>:</h4>
<p><code>Finds the full set of DefIds within the current crate that have MIR associated with them.</code></p>



<a name="217218616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218616">(Nov 19 2020 at 01:12)</a>:</h4>
<p>yeah, that does seem promising :)</p>



<a name="217218686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218686">(Nov 19 2020 at 01:12)</a>:</h4>
<p>Now that I think about it, this should help with generic and <code>#[inline]</code> functions too</p>



<a name="217218708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218708">(Nov 19 2020 at 01:13)</a>:</h4>
<p>we should emit zero counters for them if they're never invoked by the local crate</p>



<a name="217218789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218789">(Nov 19 2020 at 01:14)</a>:</h4>
<p>and if they're invoked by a downstream crate, that crate can add new counters for the same code regions (that doesn't break anything does it?)</p>



<a name="217218808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218808">(Nov 19 2020 at 01:14)</a>:</h4>
<p>(in fact this applies to any public function, not just generic or <code>#[inline]</code> ones)</p>



<a name="217218820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217218820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217218820">(Nov 19 2020 at 01:14)</a>:</h4>
<p>I <em>think</em> that's OK? They are zeros otherwise. Should just be whatever new counters + 0</p>



<a name="217219376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217219376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217219376">(Nov 19 2020 at 01:24)</a>:</h4>
<p>and assuming that works, I wonder if we can emit a single zero counter for the entire span of the body, or have to break it up into the same spans we would use if the function were being codegenned</p>



<a name="217219402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217219402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tmandry <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217219402">(Nov 19 2020 at 01:25)</a>:</h4>
<p>but I'm derailing a bit</p>



<a name="217220657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217220657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217220657">(Nov 19 2020 at 01:48)</a>:</h4>
<p>Grr   mobile app issues</p>



<a name="217220672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217220672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217220672">(Nov 19 2020 at 01:48)</a>:</h4>
<p>(deleted)</p>



<a name="217220773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217220773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217220773">(Nov 19 2020 at 01:50)</a>:</h4>
<p>I should have the computed counters but I don't want to add them because it would add unnecessary weight to the coverage map</p>



<a name="217343379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217343379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217343379">(Nov 19 2020 at 23:09)</a>:</h4>
<p>So I completed the implementation of this last night, but it doesn't work <span aria-label="unamused" class="emoji emoji-1f612" role="img" title="unamused">:unamused:</span> </p>
<p>I spent part of today trying to understand why. There are actually a couple of issues.</p>
<ol>
<li>For the original case I was trying to solve, it compiles, the binary runs, and <code>llvm-profdata</code> indexes the file, but <code>llvm-show</code> fails with `:</li>
</ol>
<div class="codehilite"><pre><span></span><code>error: if: Failed to load coverage: Malformed instrumentation profile data
</code></pre></div>
<p>As far as I can tell, the coverage map  (looking at LLVM IR, and debug logs) is consistent. Assuming that's true, I think the main difference is, the function record refers to a function (by mangled symbol) that is not defined in LLVM IR. By definition, it was not codegenned. My guess is, <code>llvm-cov</code> fails if the coverage map includes coverage for a function that does not exist.</p>
<p>Maybe my guess is wrong, but I'm not sure what other explanations might be.</p>
<ol start="2">
<li>I also tried to reproduce this by defining an unused public function in my simple test program, along with the test <code>main()</code>. I was a little surprised to see the unused function showed no coverage. It was codegenned, so my new code did not come into play. (I think <code>pub</code> functions are found by the <code>RootCollector()</code>, along with <code>main()</code>.)</li>
</ol>
<p>I'm confused by this because <code>llvm-cov show --debug</code> shows that the tool recognizes the counter for this code region:</p>
<div class="codehilite"><pre><span></span><code>Counter in file 0 3:20 -&gt; 5:2
</code></pre></div>
<p>But I'd expect the lines to show counts of <code>0</code>, and they don't. There are no counts.</p>
<p>I think the linker may be filtering it out.</p>
<p>Maybe the linker filtered out that uncalled function, but if it did, it's curious why <code>llvm-cov</code> did not fail like it did for the missing closure (my first issue above).</p>
<p>(FYI: I also tried explicitly setting <code>-C link-dead-code=on</code> (which should already be the default anyway, when using <code>-Z instrument-coverage</code>) but it didn't make a difference.)</p>
<p>I don't see any <code>llvm-cov</code> flags to force it to include stats for the counters for uncalled functions. </p>
<p>Considering both of these issues, I'm concerned that if I try to resolve problem 1 (say, but forcing the unused closure to be codegenned), it may not solve my original requirement after all. I want to see the lines/region counted (with a zero 0). </p>
<p>I may need to defer this issue if I can't find some practical workarounds.</p>



<a name="217354331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/counters%20for%20uncalled%20functions/near/217354331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Rich Kadel <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/counters.20for.20uncalled.20functions.html#217354331">(Nov 20 2020 at 02:09)</a>:</h4>
<p>FYI, I'm seeing a similar problem (same <code>llvm-cov</code> error message) in this coverage bug report: <a href="https://github.com/rust-lang/rust/issues/79175#issuecomment-730796279">https://github.com/rust-lang/rust/issues/79175#issuecomment-730796279</a></p>
<p>I've included some analysis and a possible common cause.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>